//
//  SpeclalLineDetailViewController.m
//  Commerce
//
//  Created by xiaofeifei on 15/2/16.
//  Copyright (c) 2015年 fei. All rights reserved.
//

#import "SpeclalLineDetailViewController.h"
#import "LatticePointVC.h"
#import "UMSocial.h"

@interface SpeclalLineDetailViewController ()<UMSocialUIDelegate>

@end

@implementation SpeclalLineDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navLabel.text = @"详情";
    [self getGoodsDetail];
    // Do any additional setup after loading the view from its nib.
}

- (void)getGoodsDetail{
    [SVProgressHUD showWithStatus:@"加载中" maskType:SVProgressHUDMaskTypeBlack];
    NSMutableDictionary *parameters = [GlobalData paramterDic];
    [parameters addEntriesFromDictionary:@{@"userid":_dataDic[@"UserID"]}];
    [[BaseNetwork alloc] initWithMethodUrl:[NSString stringWithFormat:@"%@car/specinfo",URL_ROOT]
                                    params:parameters
                               requestMode:DGHTTPMethodPOST
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  id responseObject = result;
                                  [SVProgressHUD dismiss];
                                  NSLog(@"responseObject=%@",responseObject);
                                  [self setDataDic:responseObject];
                                  [self configUI];
                              }];
}

- (void)getShare{
    NSString *content = [NSString stringWithFormat:@"亲，发现一个做事挺用心口碑好的物流 %@ %@ %@ %@  %@ 来自【物流百事通】真情陪伴你每一天下。下载地址（  http://www.zhi56.cn/home/ld  ）",_advantageLabel.text,_companyNameLabel.text,_telLabel.text,_comTelLabel.text,_addressLabel.text];
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:UMENG_APPKEY
                                      shareText:content
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToTencent,UMShareToEmail,UMShareToSms,nil]
                                       delegate:self];
}

- (void)configUI{
    if (_dataDic.count == 0) {
        return;
    }
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width - 70, self.navView.frame.size.height-38, 60, 30)];
    [rightBtn setTitle:@"分享" forState:UIControlStateNormal];
    [rightBtn setBackgroundImage:[UIImage imageNamed:@"back_n.png"] forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(getShare) forControlEvents:UIControlEventTouchUpInside];
    [self.navView addSubview:rightBtn];
    
    _companyNameLabel.text = [GlobalData getStringValue:_dataDic[@"CompanyName"]];
    _nameLabel.text = [GlobalData getStringValue:_dataDic[@"TrueName"]];
    _comTelLabel.text = [GlobalData getStringValue:_dataDic[@"CompanyTel"]];
    _telLabel.text = [GlobalData getStringValue:_dataDic[@"UserName"]];
    _addressLabel.text = [GlobalData getStringValue:_dataDic[@"Address"]];
    _advantageLabel.text = [GlobalData getStringValue:_dataDic[@"SpecialName"]];
    NSMutableArray *focusData = [[NSMutableArray alloc] initWithCapacity:10];
    for (int i=0; i<[_dataDic[@"Affix"] count]; i++) {
        NSString *path = [_dataDic[@"Affix"][i][@"FileName"] stringByReplacingOccurrencesOfString:@"~" withString:@""];
        NSString *imgUrl = [NSString stringWithFormat:@"%@%@",URL_ROOT_PIC,path];
        [focusData addObject:[NSDictionary dictionaryWithObjectsAndKeys:imgUrl,@"image",
                              @"pic1",@"title",
                              @NO,@"isLocal",nil]];
    }
    [_focusView configUIWithFocusdata:focusData hasTitle:NO animateInterval:3];
}

- (IBAction)callCompanyPhone:(id)sender{
    [[GlobalData sharedGlobalData] phoneBtnActWithNum:_comTelLabel.text];
    if (_comTelLabel.text.length == 0) {
        return;
    }
    //传入的参数
    NSString *user_name = [[GlobalData sharedGlobalData] userinfoDic][@"UserName"];
    if (!user_name) {
        user_name = @"";
    }
    NSString *url = [NSString stringWithFormat:@"%@user/boda?api_key=%@&user_name=%@&to_username=%@",URL_ROOT,[[@"1234567890!@#" md5HexDigest] uppercaseString],user_name,_comTelLabel.text];
    [[BaseNetwork alloc] initWithMethodUrl:url
                                    params:nil
                               requestMode:DGHTTPMethodGET
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  
                              }];

}

- (IBAction)callPhone:(id)sender{
    [[GlobalData sharedGlobalData] phoneBtnActWithNum:_telLabel.text];
    if (_telLabel.text.length == 0) {
        return;
    }
    //传入的参数
    NSString *user_name = [[GlobalData sharedGlobalData] userinfoDic][@"UserName"];
    if (!user_name) {
        user_name = @"";
    }
    NSString *url = [NSString stringWithFormat:@"%@user/boda?api_key=%@&user_name=%@&to_username=%@",URL_ROOT,[[@"1234567890!@#" md5HexDigest] uppercaseString],user_name,_telLabel.text];
    [[BaseNetwork alloc] initWithMethodUrl:url
                                    params:nil
                               requestMode:DGHTTPMethodGET
                               loadingShow:YES
                              didFinshLoad:^(id result) {
                                  
                              }];
}

- (IBAction)showAlertDetail:(id)sender{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:_dataDic[@"SpecialName"]==[NSNull null]?@"":_dataDic[@"SpecialName"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert showWithCompletionHandler:^(NSInteger buttonIndex) {
        
    }];
}

- (IBAction)gotoPoint:(id)sender{
    LatticePointVC *vc = [[LatticePointVC alloc] initWithNibName:nil bundle:nil];
    vc.dataDic = _dataDic;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
